package handle

import (
	"fmt"
	"myserver/util"
	"net/http"
)

//FuncInfo import from util pkg
type FuncInfo util.FuncInfo

// New register FuncInfo
func New() []FuncInfo {
	var fi []FuncInfo
	fi = make([]FuncInfo, 100)
	fi[0] = FuncInfo{Name: "DefaultReturnHandler1", PkgPath: "myserver/handle", FuncName: DefaultReturnHandler1, Decrib: "/"}
	fi[1] = FuncInfo{Name: "DefaultReturnHandler2", PkgPath: "myserver/handle", FuncName: DefaultReturnHandler2, Decrib: "/"}
	fi[2] = FuncInfo{Name: "UsrTokenHandler", PkgPath: "myserver/handle", FuncName: UsrTokenHandler, Decrib: "/"}

	return fi
}

func UsrTokenHandler() http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {

		fmt.Fprintf(res, "UsrTokenHandler, Welcome to the home page!")
	}
}

//DefaultReturnHandler handler func
func DefaultReturnHandler() http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(res, "DefaultReturnHandler, Welcome to the home page!")
	}
}

//DefaultReturnHandler1 handler func
func DefaultReturnHandler1() http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(res, "DefaultReturnHandler1, Welcome to the home page!")
	}
}

// DefaultReturnHandler2 /?test=xxx
func DefaultReturnHandler2() http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {

		fmt.Fprintf(res, "DefaultReturnHandler2, test = %s", req.FormValue("test"))
	}
}
